#ifndef DB_MANAGER_H_
#define DB_MANAGER_H_

#include "BasicConfig.h"
#include <QSqlQuery>
#include <QSqlTableModel>
#include <QSqlQueryModel>
#include <QApplication>
#include <QtGui> 
#include <QSqlField>
#include <QSqlIndex>
#include <QAbstractItemDelegate>

#define TABELLA_CASE "APPCASE"
#define TABELLA_PAESI "LUOGHI"

#define TABELLA_TIPO "TIPO_OGGETTI"

#define _POSTO_FR_ 21
#define _POSTO_EURO_ 22
#define _VALUTA_UPDATE_ 23
#include "Structures.h"



class DB_Manager : public QObject
{
	Q_OBJECT
	
public:
	DB_Manager();
	virtual ~DB_Manager();
	bool Connect( const QString sheme , int trac = 0);
  inline QString scheme() const { return Actual_Scheme; }
  int NuovoOggetto();
  void  GrepOrfani();
  bool CestinaId( const int id );
	int IdTipo( const int tipoditurismo );
	QString TipoNome( const int idnostro );
  bool HavingIDOggetto( const int id );
  bool NuovoOggettoID( const int id , uint timer );
  int IdPaese( const int titurism );
  bool UpdatesOggetti( const int titurism , int localid , QMap<QString,QString> fupdates , const int tipo = 2 );
  void Load();
  QMap<QString,QStringList>  retranslate_now();
  inline QString GetIcons() const { return StreamIcone; }
  void FillBoxRegioni( QComboBox * box , int id );
	void FillBoxLuoghi( QComboBox * boxtipo, int id , int modus = 0 );
  void FillBoxTipo( QComboBox * boxtipo, int id = 1 , int modus = 0 );
	void ExportAllTable();   /* remote mysql dump */
	QIcon createColorToolButtonIcon( QColor e  );
  bool Save_Setting( const int stnr , const QString stream , const QString t = QString("APPLICATION_SETTING"));
  QString Get_Setting( const int stnr , const QString t = QString("APPLICATION_SETTING") );
	bool Save_Calendar( const int stnr , const QString stream , const QString web );
	QString Get_Calendar( const int stnr );
	
	inline void Purge() { 
			QSqlDatabase::removeDatabase(ConnectionName); 
	}
	inline bool isValid() {
		return db.isOpen();
	}
	inline QString info() { return infodb; }
	QString TableMysqlStruct( const QString table , 
			                  QSqlDatabase db , 
			                  bool dropbefore , 
			                  bool space = false );
	QString StreamTableDump( const QString table , 
			                QSqlDatabase dbcurrent , 
			                int forcecodecmib = 0 );
	inline QSqlDatabase current() { return db; } 
	inline QString dbtype() { return type; } 
	void FillCombo(  QComboBox  *  box );
	void FillComboFixQuery(  QComboBox  *  box );
	QStringList FieldList( const QString table );
	QStringList DefaultFieldFrom( const QString table , 
			                  QSqlDatabase dbcurrent ) ;   /* default value insert! */
	inline QStringList Hotlist() { return hottables; }
	inline QMap<QString,QStringList> Translated_Doc() { return trdoc; }
	QString ConnectionName;
	bool UpDateQuery( const QString ese , QSqlDatabase dbcurrent );
	bool UpDateQuery( const QString ese );
	protected:
	QString Actual_Scheme;
	QMap<QString,QStringList> trdoc;
	QString infodb;
	QString StreamIcone;
	QStringList hottables;
	QSqlDatabase db;
	QString type;
	private:
	signals:
	public slots:
};

#endif /*DB_MANAGER_H_*/  
